package com.mosai.alignpro.util;

import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;

import com.mosai.alignpro.R;
import com.mosai.alignpro.entity.ImageInfo;
import com.mosai.alignpro.view.AlertDialog;

/**
 * Created by Rays on 2020/3/23.
 */
public final class DialogUtils {

    public static void showRemoveAngleDialog(Context context, DialogUtils.OnClickListener onClickListener) {
        new AlertDialog.Builder(context)
                .setTitle(R.string.cancel_edit_dialog_title)
                .setMessage(R.string.mgs_dialog_remove_angle)
                .setPositiveButton(R.string.dialog_btn_confirm, onClickListener)
                .setNegativeButton(R.string.dialog_btn_cancel, onClickListener)
                .setCancelable(false)
                .create()
                .show();
    }

    public static void showCancelEditDialog(Context context, DialogUtils.OnClickListener onClickListener) {
        new AlertDialog.Builder(context)
                .setTitle(R.string.cancel_edit_dialog_title)
                .setMessage(R.string.cancel_edit_dialog_msg)
                .setPositiveButton(R.string.dialog_btn_confirm, onClickListener)
                .setNegativeButton(R.string.dialog_btn_cancel, onClickListener)
                .setCancelable(false)
                .create()
                .show();
    }

    public static void showPendingFinishDialog(Context context, DialogUtils.OnClickListener onClickListener) {
        new AlertDialog.Builder(context)
                .setTitle(R.string.cancel_edit_dialog_title)
                .setMessage(R.string.pending_finish_dialog_msg)
                .setPositiveButton(R.string.dialog_btn_confirm, onClickListener)
//                .setNegativeButton(R.string.dialog_btn_cancel, onClickListener)
                .setCancelable(false)
                .create()
                .show();
    }

    public static void showDescribeDialog(Context context, ImageInfo info, DialogUtils.OnClickListener onClickListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context)
                .setMessage(info.getNewDescribe())
                .setMessageGravity(Gravity.START)
                .setNegativeButton(R.string.dialog_btn_cancel, onClickListener);
        if (info.isEditing()) {
            builder.setPositiveButton(R.string.diagnosis_edit, onClickListener);
        }
        builder.show();
    }

    public static abstract class OnClickListener implements DialogInterface.OnClickListener {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            onClick(dialog, which == DialogInterface.BUTTON_POSITIVE);
        }

        protected abstract void onClick(DialogInterface dialog, boolean isPositive);
    }

}
